package com.cmii.sjw.department.control.jsc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cmii.sjw.department.control.jsc.model.params.SchoolInfoParams;
import com.cmii.sjw.department.control.jsc.service.SocialPracticeBasesService;
import com.cmii.sjw.department.control.jsc.util.Result;
import com.cmii.sjw.department.control.jsc.vo.PracticeBaseInfoVO;
import com.cmii.sjw.department.control.jsc.vo.SchoolInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 社会实践基地信息
 *
 * @Author jfh
 * @Date 2025-02-11 周二 9:16
 * @Version 1.0
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/socialPracticeBases")
public class SocialPracticeBasesController {


    @Autowired
    private SocialPracticeBasesService socialPracticeBasesService;

    /**
     * 确认地址信息
     *
     * @return
     */
    @PostMapping("/confirmeAaddressInfo")
    public Result confirmeAaddressInfo() {
        return socialPracticeBasesService.confirmeAaddressInfo();
    }

    /**
     * 基地名称列表
     *
     * @return 根据名称查询
     * @author lizheng
     * @date 2025-2-13
     */
    @PostMapping("/social")
    public Result<IPage<String>> getSocialNames(@RequestParam(defaultValue = "1") Integer current,
                                                @RequestParam(defaultValue = "10") Integer size,
                                                String districtName, String name) {
        IPage<String> result;
        if (districtName != null && !districtName.isEmpty()) {
            result = socialPracticeBasesService.getSocialNamesByDistrict(districtName, current, size);
        } else if (name != null && !name.isEmpty()) {
            result = socialPracticeBasesService.getSocialNamesByName(name, current, size);
        } else {
            result = socialPracticeBasesService.getAllSocialNames(current, size);
        }
        return Result.success(result);
    }

    /**
     * 统计
     *
     * @return 根据地区统计数量
     * @author lizheng
     * @date 2025-2-13
     */
    @PostMapping("/statistics")
    public Result countByDistrict() {
        Map<String, Object> result;
        result = socialPracticeBasesService.countByDistrict();
        return Result.success(result);
    }

    /**
     * 获取社会实践基地地图信息
     *
     * @param params
     * @return
     */
    @PostMapping("/industryEducationMapDetailed")
    public Result socialPracticeBasesMapDetailed(SchoolInfoParams params) {
        return socialPracticeBasesService.socialPracticeBasesMapDetailed(params);
    }

    /**
     * 中小学实践基地
     *
     * @return 数据入库
     */
    @PostMapping("/saveData")
    public Result saveData() {
        socialPracticeBasesService.saveData();
        return Result.success();
    }

    /**
     * 中小学实践基地首页
     *
     * @return 首页展示
     */
    @PostMapping("/index")
    public Result<List<PracticeBaseInfoVO>> index() {
        return Result.success(socialPracticeBasesService.index());
    }
}
